<?php
	
	//---------------------------------------
	function url($link){
		header('location:'.$link);
	}
	//---------------------------------------
	 function file_size($link){ 
		$remoteFile=$link;
		$ch = curl_init($remoteFile);
		curl_setopt($ch, CURLOPT_NOBODY,true);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch,CURLOPT_HEADER, true);
		curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
		$data=curl_exec($ch);
		curl_close($ch);$contentLength='Unknown';
		(preg_match('/Content-Length: (\d+)/', $data,$matches))?$contentLength=round(((int)$matches[1])/1024/1024,2):'';
		return $contentLength;
	}
		//---------------------------------------
	 function download($filename,$filepath,$mimetype){
		header('Cache-Control: ');
		header('Content-Description: File Transfer');
		header('Content-Disposition: attachment; filename='.$filename);
		header('Content-Type:'.$mimetype);
		header('Content-Transfer-Encoding: binary');  
		return readfile($filepath);
	}
		//---------------------------------------
	 function timeago($time){
		$longtime=time()-$time;
		if ($longtime>=31556926) $result=round($longtime/31556926,0).' năm'; else 
			if ($longtime>=2629743)  $result=round($longtime/2629743,0).' tháng'; else 
				if ($longtime>=86400) $result=round($longtime/86400,0).' ngày'; else 
					if ($longtime>=3600) $result=round($longtime/3600,0).' giờ'; else 
						if ($longtime>=60) $result=round($longtime/60,0).' phút'; else 
							$result=$longtime.' giây'; 
		return $result;
	}
	//---------------------------------------
	 function timeformat($time){
		($time==0)?$thoigian='Không thể xác định !':$thoigian = date("d/m/Y [H:i]", $time);
		return $thoigian;
	}
	//--------------------------------------- edit by leminh0792
	function alert($status){
        echo '<script type="text/javascript">
            alert("'.$status.'");
            </script>';
	}
		
	//---------------------------------------	
		
		